#ifndef IACTION_H
#define IACTION_H
#include <QObject>
#include <QJsonObject>

enum ActionResult
{
    ARSuccess,
    ARCondition, //执行条件不满足
    ARError,     //发生错误，中断不可重试和继续.
};

class IAction : public QObject
{
    Q_OBJECT

public:
    //把前置动作的结果汇入参数.
    void setPrevResult(const QJsonObject &param){
        //actParam.insert("prev",QJsonValue(param));
        prevResult = param;
    }
    const QJsonObject& getResult(){
        return actResult;
    }
    //把act设为自己的下线，对应位置index
    void setNext(IAction* act,int index=0);
    //把自己设为act的下线，对应index位置.
    void setPrev(IAction* act,int index=0);

    int doExec(); //参见execute的说明.
    QString name(){return classname;}
    QString msg(){return message;}
//signals:
//    void sigExecuteDone(int _ActionResult, IAction* ptr);
    IAction* getNext(int index=0);

    static int freeAllActions();
protected:
    IAction();
    virtual ~IAction();
    QString classname;
    QString message;
    QJsonObject actParam;  //操作参数.
    QJsonObject actResult; //返回值。覆盖.
    static QJsonObject prevResult; //上一动作的结果

    //使用actParam作为参数执行动作. 可以使用个性函数来配置actParam
    //返回-1失败，0是默认成功，1、2、3分支选择. -2是挂起.
    virtual int execute()=0;
    //下一个action，提供多个出口，默认是0号条件型提供多个出口.
    QList<IAction*> actionNext;

private:
    static QList<IAction*> allActions;
};

#include "actioncompositekey.h"
#include "actioncondition.h"
#include "actionfindqqlogin.h"
#include "actionfindwindow.h"
#include "actionhold.h"
#include "actioninput.h"
#include "actionkill.h"
#include "actionmatch.h"
#include "actionmouse.h"
#include "actionprocess.h"
#include "actionqqlogin.h"
#include "actionrelativepos.h"
#include "actionwait.h"
#endif // IACTION_H
